package cn.middle.remote.handler.decodec;

import java.util.List;

import cn.middle.remote.message.AckSignal;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;

public class AckCodec implements Codec<AckSignal> {

	@Override
	public void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out, int beginIndex) throws Exception {
		if(in.readableBytes() < 4) {
			in.readerIndex(beginIndex);
			return ;
		}
		
		int msgIdLength = in.readInt();
		if(in.readableBytes() < msgIdLength) {
			in.readerIndex(beginIndex);
			return ;
		}
		String msgId = CodecUtil.context(in, msgIdLength);
		AckSignal ack = new AckSignal(msgId);
		out.add(ack);
	}
	

	@Override
	public void encode(ChannelHandlerContext ctx, AckSignal msg, ByteBuf out) throws Exception {	
	}

}
